#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int* plusOne(int* digits, int digitsSize, int* returnSize) {
    for (int i = digitsSize - 1; i >= 0; i--)
    {
        if (digits[i] == 9)
            digits[i] = 0;
        else
        {
            digits[i]++;
            *returnSize = digitsSize;
            return digits;
        }
    }

    int* p = (int*)malloc(sizeof(int) * (digitsSize + 1));
    memset(p, 0, sizeof(int) * (digitsSize + 1));
    p[0] = 1;   
    *returnSize=digitsSize+1;
    return p;
}

int main()
{
    int ret = 0;
    int arr[10] = { 9,9,9,9,9,9,9,9,9,9 };
    int* p = plusOne(arr, 10, &ret);
    for (int i = 0; i < ret; i++)
    {
        printf("%d ", p[i]);
    }
    return 0;
}